# 设置交叉编译工具链
CROSS_COMPILE := arm-linux-
ARCH := arm

AS      = $(CROSS_COMPILE)as
LD      = $(CROSS_COMPILE)ld
CC      = $(CROSS_COMPILE)gcc
CPP     = $(CC) -E
AR      = $(CROSS_COMPILE)ar
NM      = $(CROSS_COMPILE)nm
STRIP   = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump

export AS LD CC CPP AR NM 
export STRIP OBJCOPY OBJDUMP

SRCARCH := $(ARCH)

# Additional ARCH settings for arm
ifeq ($(ARCH), arm)
	SRCARCH := arm
endif

CFLAGS := -Wall -Werror -O2 -g
LDFLAGS := 

TOPDIR := $(shell pwd)
export TOPDIR

TARGET := image.bin

# 设置芯片信息
SOC_MANFAC := sumsung
SOC_NAME := s3c2440

# 添加 头文件路径信息

INC_ROOT_PATH:= $(TOPDIR)/include

INC_DIRS := $(INC_ROOT_PATH)/ \
			$(INC_ROOT_PATH)/arch/$(ARCH)/armv5 \
			$(INC_ROOT_PATH)/bsp/common \
			$(INC_ROOT_PATH)/bsp/board/$(SOC_MANFAC)/$(SOC_NAME) \
			$(INC_ROOT_PATH)/base \
			$(INC_ROOT_PATH)/io/fileio \
			$(INC_ROOT_PATH)/kernel \
			$(INC_ROOT_PATH)/kernel/device \
			$(INC_ROOT_PATH)/kernel/driver \
			$(INC_ROOT_PATH)/kernel/intrpt \
			$(INC_ROOT_PATH)/kernel/mem \
			$(INC_ROOT_PATH)/kernel/sem \
			$(INC_ROOT_PATH)/kernel/task \
			$(INC_ROOT_PATH)/kernel/time \
			$(INC_ROOT_PATH)/libs/libapi \
			$(INC_ROOT_PATH)/libs/libc \
			$(INC_ROOT_PATH)/service \
			$(INC_ROOT_PATH)/syscall \
			
H_FILES := $(patsubst %, -I %, $(INC_DIRS))

CFLAGS += $(H_FILES)

# Objects we will link into hyper / subdirs we need to visit

obj-y += arch/$(SRCARCH)/
obj-y += bsp/common/
obj-y += bsp/board/$(SOC_MANFAC)/$(SOC_NAME)/
obj-y += obj/
obj-y += core/
obj-y += drivers/
obj-y += fs/
obj-y += libs/
obj-y += samples/

$(info $(obj-y))

all:
	make -C ./ -f $(TOPDIR)/Makefile.build
	$(CC) $(LDFLAGS) -o $(TARGET) build-in.o

clean:
	rm -f $(shell find -name "*.o")
	rm -f $(TARGET)
